package com.beta.em;

import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * Created by vector on 2016/11/19.
 */
public enum UserType {

    RETAILER("retailer", "零售商"),
    DEALER("dealer", "贸易商"),
    COURIER("courier", "承运人");

    private String value;
    private String cnValue;

    UserType(String value, String cnValue) {
        this.value = value;
        this.cnValue = cnValue;
    }

    public String getValue() {
        return this.value;
    }

    public String getCnValue() {
        return this.cnValue;
    }

    public static boolean isCourierType(String username) {
        return StringUtils.startsWithIgnoreCase(username, "w");
    }

    public static UserType getUserType(String value) {
        for (UserType userType: values()) {
            if (userType.getValue().equals(value)) {
                return userType;
            }
        }
        return null;
    }

    public static String getCnValue(String value) {
        UserType type = getUserType(value);
        if (Objects.nonNull(type)) {
            return type.getCnValue();
        } else {
            return "";
        }
    }

}
